#pragma once

#include <D3D11.h>
#include <Windows.h>
#include <xnamath.h>

#include "Texture.h"


namespace TestDX
{

// @ TODO: Add texturing
class Model
{
private:
	struct Vertex
	{
		XMFLOAT3 position;
		XMFLOAT2 texture;
		XMFLOAT3 normal;
	};

	typedef unsigned long Index;

	// Struct to handle data from our file format
	struct TModel
	{
		float x, y, z;
		float tu, tv;
		float nx, ny, nz;
	};

public:
	Model(void);
	~Model(void);

	bool Init(ID3D11Device *, WCHAR *, WCHAR *);
	void Shutdown();
	void Render(ID3D11DeviceContext *);

	inline int GetIndexCount();
	inline ID3D11ShaderResourceView * GetTexture();

private:
	// Copy and assign are forbidden
	Model(const Model &);
	Model & operator=(const Model &);

	bool InitBuffers(ID3D11Device *);
	void ShutdownBuffers();

	void RenderBuffers(ID3D11DeviceContext *);

	bool LoadTexture(ID3D11Device *, WCHAR *);
	void ReleaseTexture();

	// Functions to load/unload model from text file in own format
	bool LoadModel(WCHAR *);
	void ReleaseModel();

	ID3D11Buffer * _pVertexBuffer, * _pIndexBuffer;
	int _vertexCount, _indexCount;

	TModel * _pModel;
	Texture * _pTexture;
};

int Model::GetIndexCount()
{
	return _indexCount;
}

ID3D11ShaderResourceView * Model::GetTexture()
{
	return _pTexture->GetTexture();
}

}